package com.ophiux.FeverManagement.api.portImpl;

import java.lang.reflect.Type;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.google.gson.reflect.TypeToken;
import com.ophiux.FeverManagement.api.port.ITreatmentPort;
import com.ophiux.FeverManagement.aplication.bean.getTreatmentListRequest;
import com.ophiux.FeverManagement.aplication.bean.getTreatmentListResponse;
import com.ophiux.FeverManagement.aplication.service.IGetTreatmentListAppPort;
import com.ophiux.micro.core.application.Request;
import com.ophiux.micro.core.application.Result;
import com.ophiux.micro.core.application.ResultEnum;
import com.ophiux.utils.parser.json.JsonUtils;
import com.ophiux.utils.parser.json.JsonUtils.TypeObtainCallback;

import lombok.extern.slf4j.Slf4j;


@Service
@Slf4j
public class TreatmentService implements ITreatmentPort{
	@Autowired
	IGetTreatmentListAppPort getTreatmentListAppPort;
		
	@Override
	public String getTreatmentList(String data) {
		log.info("getTreatmentList接口,请求参数："+data);
		Result<List<getTreatmentListResponse>> result = null;
		Request<getTreatmentListRequest> request = null;
		try {
			request = JsonUtils.toEntity(data, new TypeObtainCallback() {
				public Type getObtainType() {
					return new TypeToken<Request<getTreatmentListRequest>>() {
					}.getType();
				}
			});
			result = getTreatmentListAppPort.execute(request.getPARAM());

			String returnMessage = JsonUtils.toJson(result);
			log.info("getTreatmentList接口,请求参数："+data+"\n getTreatmentList接口,返回参数："+returnMessage);
			return returnMessage;
		} catch (Exception e) {
			e.printStackTrace();
			log.info("getTreatmentList接口异常",e);
			result = Result.fail(ResultEnum.requestException);
			return JsonUtils.toJson(result);
		}
	}

}
